package com.zjhn.ds.controller.app.pad;

import com.alibaba.fastjson.JSON;
import com.zjhn.ds.common.BizResult;
import com.zjhn.ds.domain.dto.mt.*;
import com.zjhn.ds.param.CompleteTaskParam;
import com.zjhn.ds.param.FinishTaskParam;
import com.zjhn.ds.param.StationMonitorParam;
import com.zjhn.ds.service.StationMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.controller.app.pad
 * @Author: sxt
 * @CreateTime: 2023-10-05  13:52
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/jlw/monitor")
@Api(tags = "pad端机台监控接口")
public class StationMonitorController {

    @Resource
    private StationMonitorService stationMonitorService;

    @ApiOperation("pad机台监控页面数据")
    @PostMapping("/stationMonitor")
    public BizResult<StationMonitorDto> stationMonitor(@RequestBody @Valid StationMonitorParam param) {
        log.info("====[INFO]========StationMonitorController====stationMonitor param:{}", JSON.toJSONString(param));
        return stationMonitorService.stationMonitor(param);
    }

    @ApiOperation("pad获取工位当前刷卡任务")
    @GetMapping("/currentTask")
    public BizResult<CurrentTaskDto> currentTask(@RequestParam("station_id") String stationId) {
        log.info("====[INFO]========StationMonitorController====currentTask stationId:{}", stationId);
        return stationMonitorService.currentTask(stationId);
    }

    @ApiOperation("pad派工任务完成")
    @PostMapping("/finishTask")
    public BizResult<?> finishTask(@RequestBody @Valid FinishTaskParam param) {
        log.info("====[INFO]========StationMonitorController====finishTask param:{}", JSON.toJSONString(param));
        return stationMonitorService.finishTask(param);
    }

    @ApiOperation("pad获取工位排队任务")
    @GetMapping("/queueTask")
    public BizResult<List<QueueTaskDto>> queueTask(@RequestParam("station_id") String stationId) {
        log.info("====[INFO]========StationMonitorController====queueTask stationId:{}", stationId);
        return stationMonitorService.queueTask(stationId);
    }

    @ApiOperation("pad获取工位已完成任务")
    @PostMapping("/completeTask")
    public BizResult<List<CompleteTaskDto>> completeTask(@RequestBody @Valid CompleteTaskParam param) {
        log.info("====[INFO]========StationMonitorController====completeTask param:{}", JSON.toJSONString(param));
        return stationMonitorService.completeTask(param);
    }

    @ApiOperation("pad完成任务激活")
    @GetMapping("/activeTask")
    public BizResult<?> activeTask(@RequestParam("assign_task_id") String assignTaskId) {
        log.info("====[INFO]========StationMonitorController====activeTask assignTaskId:{}", assignTaskId);
        return stationMonitorService.activeTask(assignTaskId);
    }

    @ApiOperation("pad获取报工信息")
    @GetMapping("/reportRecord")
    public BizResult<List<ReportRecordDto>> reportRecord(
            @RequestParam("station_id") String stationId,
            @RequestParam("pro_task_detail_id") String proTaskDetailId
    ) {
        log.info("====[INFO]========StationMonitorController====reportRecord stationId:{}, proTaskDetailId:{}", stationId, proTaskDetailId);
        return stationMonitorService.reportRecord(stationId, proTaskDetailId);
    }

    @ApiOperation("pad删除报工信息")
    @GetMapping("/removeRecord")
    public BizResult<?> removeRecord(
            @RequestParam("report_record_id") String reportRecordId
    ) {
        log.info("====[INFO]========StationMonitorController====removeRecord reportRecordId:{}", reportRecordId);
        return stationMonitorService.removeRecord(reportRecordId);
    }
}
